﻿@using ETD.Common.Extension;
@using ETD.WebOrganization.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@using ETD.WebOrganization.Libs.Controls;
@model ETD.WebOrganization.Areas.Web.Models.Feedback.FeedbackDetailModel
@{
    ViewBag.Title = "设备管理";
}
@{

}
<style>
    .text-left {
        text-align: left;
    }

    .securityCheckItem-name {
        font-size: 16px !important;
        line-height: 2 !important;
    }

    .weui-form-preview:after {
        border-bottom: 0px solid #e5e5e5 !important;
    }



    .btnActions {
        margin-top: 15px;
    }

    .weui-btn_primary {
        background-color: #4dd1c1;
        width: 80% !important;
    }

    .head-img {
        border-radius: 12.5px;
        width: 25px;
        height: 25px;
        margin-left: 18px;
        margin-right: 10px;
    }
        .weui-actionsheet__title {
        height: 0px !important;
    }

    .weui-actionsheet__title_sub {
        height: 30px !important;
        font-size: 14px;
        color: gray;
        padding: 0px;
        line-height: 30px;
        text-align: left;
        padding-left: 20px;
        background-color: #f7f7f7;
    }
</style>
<div id="contentContainer" class="weui-form-preview">
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">设备号</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" readonly v-bind:value="modelData.FacilityCode" />
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">故障类型</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" readonly v-bind:value="modelData.OrganizationName" />
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">医院</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" readonly v-bind:value="modelData.OrganizationName" />
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">科室</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" readonly v-bind:value="modelData.SectionOfficeName" />
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">状态</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" readonly v-bind:value="modelData.FeedbackStatusName" />
            </div>
        </div>
    </div>
    @*<div class="weui-cells__title">备注</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <textarea id="txtDescription" class="weui-textarea weui-form-preview__value" placeholder="请填写备注" rows="3" maxlength="200"></textarea>
                </div>
            </div>
        </div>*@

    <div class="weui-flex btnActions">
        <div class="weui-flex__item">
            <div class="placeholder">
                <button id="btnComment" type="submit" class="weui-btn weui-btn_primary" href="javascript:"
                        style="margin-top:0px;">
                    备注
                </button>
            </div>
        </div>
        <div class="weui-flex__item">
            <div class="placeholder">
                <button id="btnSubmit" type="submit" class="weui-btn weui-btn_primary" href="javascript:"
                        style="margin-top:0px;">
                    操作
                </button>
            </div>
        </div>

    </div>

    <div class="weui-cells__title">备注列表</div>
    <div class="weui-cells">

        <div class="weui-cell" v-for="(item, index) in itemList">
            <div class="weui-cell__hd" style="text-align:center;width:60px;word-break:break-all;">
                <img class="weui-media-box__thumb head-img" src="@Url.MapMvcAssets("NormalImages/me_gray.png")" />
                <span style="font-size:12px;color:gray;">{{item.CreateByUserInfoRealName}}</span>

            </div>
            <div class="weui-cell__bd" style="padding-left:5px;">
                <div> {{item.Comment}}   </div>
                <span style="font-size:12px;color:gray;float:right;">{{toYmdhmsTime(item.CreateAt)}}</span>
            </div>

        </div>
        <div class="weui-loadmore" v-show="loading" style="margin-bottom:100px;">
            <i class="weui-loading"></i>
            <span class="weui-loadmore__tips">{{loadingText}}</span>
        </div>
        @*没有更多数据后，占位符，因为这里有一个添加按钮，占走了很多高度*@
        <div class="no-more-data-placehoder" v-show="!loading" style="margin-bottom:100px;">
        </div>
    </div>

</div>
<div id="popComment" class='weui-popup__container popup-bottom'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="toolbar">
            <div class="toolbar-inner">
                <a href="javascript:;" class="picker-button close-popup">关闭</a>
                <h1 class="title">添加备注</h1>
            </div>
        </div>
        <div class="modal-content">
            <div class="weui-cell">
                <textarea id="txtComment" class="weui-textarea weui-form-preview__value" placeholder="请输入备注" rows="3"></textarea>
            </div>

            <div class="weui-form-preview__ft">
                <button id="btnPopCommentOk" type="submit" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:">确认</button>
                <a class="weui-form-preview__btn weui-form-preview__btn_default" href="javascript:$.closePopup();">取消</a>
            </div>
        </div>
    </div>
</div>

@section ScriptSection{
    <script>
        var pageVue = new Vue({
            el: '#contentContainer',
            data: {
                itemList: [],
                modelData: {},
                page: 0,
                hasMore: true,
                loading: false,
                loadingText: '向上滑动加载更多...'
            },
            created () {
                let self = this;
                this.getModelData();
                this.getItemList();
                this.scrollBottom();
            }
             ,
            mounted () {
                // 添加滚动事件，检测滚动到页面底部
                //window.addEventListener('scroll', this.scrollBottom)
            },
            methods: {
                scrollBottom: function () {
                    let self = this;
                    var baseVue = new BaseVue();
                    baseVue.scrollBottom(self);
                },
                onFacilityItemLinkClick: function (item) {
                    PageObj.onFacilityItemLinkClick(item.FacilityID);
                },
                decimalF2: function (num) {
                    return StringHelper.decimalF2(num);
                },
                toYmdhmsTime: function (time) {
                    return TimeHelper.ymdhmsTime(time);
                },
                getModelData: function () {
                    var feedbackID = WinHelper.getUrlParam("feedbackID");
                    var url = '@Url.Action("FindFeedback", "Feedback")';
                    url = WinHelper.urlWrap(url);
                    var paras = {};
                    paras.FeedbackID = feedbackID;
                    paras.CurrentPageIndex = self.page;
                    showCommonLoading();
                    // 获取今日新闻
                    axios.post(url, paras)
                      .then((res) => {
                          hideCommonLoading();
                          console.log(res.data);
                          this.bindModelData(res.data);
                      });
                },
                bindModelData: function (data) {
                    let self = this;
                    self.modelData = data.Data;
                },
                refreshItemList: function () {
                    let self = this;
                    self.hasMore = false;
                    self.loading = true;
                    self.loadingText = '努力加载中...';
                    self.page = 0;
                    self.itemList = [];
                    self.getItemList();
                },
                getItemList: function () {
                    let self = this;
                    var feedbackID = WinHelper.getUrlParam("feedbackID");
                    var url = '@Url.Action("FindFeedbackCommentList", "Feedback")';
                    url = WinHelper.urlWrap(url);
                    var paras = {};
                    paras.FeedbackID = feedbackID;
                    paras.CurrentPageIndex = self.page;
                    showCommonLoading();
                    // 获取今日新闻
                    axios.post(url, paras)
                      .then((res) => {
                          hideCommonLoading();
                          console.log(res.data);
                          this.bindItemList(res.data);
                      });
                },
                bindItemList: function (data) {
                    let self = this;
                    $.each(data.Data.FeedbackCommentList, function (i, item) {
                        self.itemList.push(item);
                    });

                    self.loadingText = '向上滑动加载更多...'
                    if (self.itemList.length >= data.TotalCount) {
                        self.loadingText = "没有更多数据了...";
                        self.hasMore = false;
                        self.loading = false;
                    } else {
                        self.hasMore = true;
                    }
                }
            }
        })
    </script>
    <script>
        $(function () {
            $(window).scrollTop(0);
            PageObj.init();
        });
        var PageObj = {};
        PageObj.init = function () {
            $("#btnSubmit").click(PageObj.onBtnSubmitClick);
            $("#btnComment").click(PageObj.onBtnCommentClick);
            $("#btnPopCommentOk").click(PageObj.onSubmitCommentClick);

        }
        PageObj.onBtnCommentClick = function () {
            $("#popComment").popup();
        }
        PageObj.onSubmitCommentClick = function () {
            var paras = {};
            paras.FeedbackID = WinHelper.getUrlParam("feedbackID");
            paras.Comment = $("#txtComment").val().trim();
            if (StringHelper.isNullOrEmpty(paras.Comment)) {
                $.toptip('请填写备注内容', 'warning');
                return;
            }

            console.log(JSON.stringify(paras));
            $.confirm("确定提交新备注吗?", "确认?", function () {
                $.closePopup();
                ajaxPost("@Url.ActionTS("FeedbackCommentEdit", "Feedback")", paras, function (data) {
                    console.log(data);
                    $("#txtComment").val("");
                    if (data.Status) {
                        pageVue.getModelData();
                        pageVue.refreshItemList();
                    } else {
                        $.toast(data.Info, "forbidden");
                    }
                });
            });
        }
        PageObj.onBtnSubmitClick = function () {
            @*$.confirm("确定处理完成吗?", "确认?", function () {
                PageObj.updateFeedbackStatus("@((int)EFeedbackStatus.Processed)");
            });*@
            $.actions({
                title: "",
                onClose: function () {
                    console.log("close");
                },
                actions: [
                  {
                      text: "更改状态",
                      className: "weui-actionsheet__title_sub",
                      onClick: function () {
                          //$.alert("你选择了“状态”");
                      }
                  },
                  {
                      text: "未处理",
                      className: 'color-warning',
                      onClick: function () {
                         PageObj.updateFeedbackStatus("@((int)EFeedbackStatus.NotProcess)");
                      }
                  },
                  {
                      text: "已处理",
                      className: 'color-primary',
                      onClick: function () {
                          PageObj.updateFeedbackStatus("@((int)EFeedbackStatus.Processed)");
                      }
                  }
                ]
            });

        }
        PageObj.updateFeedbackStatus = function (feedbackStatusID) {
            var paras = {};
            paras.FeedbackID = WinHelper.getUrlParam("feedbackID");
            paras.FeedbackStatusID = feedbackStatusID;
            console.log(JSON.stringify(paras));

            ajaxPost("@Url.ActionTS("UpdateFeedbackStatus", "Feedback")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast(data.Info);
                    pageVue.getModelData();
                } else {
                    $.toast(data.Info, "forbidden");
                }
            });
        }
    </script>
}